package com.example.imitation_webchat_demo.fragment;

import java.util.ArrayList;
import java.util.List;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.example.imitation_webchat_demo.R;
import com.example.imitation_webchat_demo.activity.SettingActivity;
import com.example.imitation_webchat_demo.adapter.MineAdapter;
import com.example.imitation_webchat_demo.entity.MineItem;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

// 我的信息页面
public class MineFragment extends Fragment {
	@ViewInject(R.id.mine_listview)
	private ListView listView;
	
	private MineAdapter adapter;
	private List<MineItem> list;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_mine, container, false);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
		ViewUtils.inject(this, getActivity());
		
		initComponent();    //初始化控件
		addListener();      //添加监听
	}
	
	//初始化控件
	private void initComponent(){
		list = new ArrayList<MineItem>();
		MineItem item = new MineItem(R.drawable.alh, "收藏");
		list.add(item);
		item = new MineItem(R.drawable.alh, "表情");
		list.add(item);
		item = new MineItem(R.drawable.alh, "设置");
		list.add(item);
		adapter = new MineAdapter(getActivity(), list);
		listView.setAdapter(adapter);
	}
	
	// 添加监听
	private void addListener(){
		listView.setOnItemClickListener(new OnItemClickListener(){
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Intent intent = null;
				switch(position){
				case 0:
					break;
				case 1:
					break;
				case 2:
					intent = new Intent(MineFragment.this.getActivity(), SettingActivity.class);
					break;
				}
				MineFragment.this.getActivity().startActivity(intent);
			}
		});
	}
}